﻿using RestSharp;
using ServiceStack.Web;
using System;
using System.Web;
using Ymatou.ServiceCenter;
using YmtAuth.AppService;
using YmtAuth.AppService.JavaService;
using YmtAuth.Domain.Shard;
using YmtAuth.Dto;
using YmtSystem.CrossCutting;
using ResetService = ServiceStack.Service;

namespace YmtAuth.Web.Handlerv2
{

    public class LoginSafeHandler : ResetService
    {
        private ILoginSafeAppService loginSafeAppService { get { return LocalServiceLocator.GetService<ILoginSafeAppService>(); } }

        /// <summary>
        /// 获取最近X天的用户（登录名）登录风控日志（pc, app）
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [ServiceRegister("/json/reply/GetLoginSafeStatusRequestDto", Method.GET)]
        public object Get(GetLoginSafeStatusRequestDto request)
        {
            HttpContext.Current.Request.Headers.Add(YmtUserKey.RequestId, Guid.NewGuid().ToString("N"));
            HttpContext.Current.Request.Headers.Add(YmtAuthSafeConstant.ApiId, YmtAuthSafeConstant.Api_login);

            return loginSafeAppService.GetLoginSafeStatus(request, Request);
        }

        /// <summary>
        /// 更新用户指定IP区域认证状态为“已认证”
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [ServiceRegister("/json/reply/IpAreaAuthManageRequestDto", Method.GET)]
        public object Get(IpAreaAuthManageRequestDto request)
        {
            HttpContext.Current.Request.Headers.Add(YmtUserKey.RequestId, Guid.NewGuid().ToString("N"));
            HttpContext.Current.Request.Headers.Add(YmtAuthSafeConstant.ApiId, YmtAuthSafeConstant.Api_login);

            return loginSafeAppService.AuthIpAreaInfoSuccess(request, Request);
        }

        /// <summary>
        /// 更新用户的所有 设备/ClientId 认证状态为“已认证”
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [ServiceRegister("/json/reply/DeviceAuthManageRequestDto", Method.GET)]
        public object Get(DeviceAuthManageRequestDto request)
        {
            HttpContext.Current.Request.Headers.Add(YmtUserKey.RequestId, Guid.NewGuid().ToString("N"));
            HttpContext.Current.Request.Headers.Add(YmtAuthSafeConstant.ApiId, YmtAuthSafeConstant.Api_login);

            return loginSafeAppService.AuthUserDeviceSuccess(request, Request);
        }
    }
}